/*
 * Copyright (C) 2008 Rob Cash
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * 	http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.robcash.apps.messagepopup.vo.impl;

import org.robcash.apps.messagepopup.vo.*;
import java.util.Date;
import java.util.Set;
import org.robcash.apps.messagepopup.util.ScheduleUtils;

/**
 * 
 * @author Rob
 */
public class ScheduleImpl implements Schedule {

    private String name;
    private Set<Integer> days;
    private Date startTime;
    private Date endTime;
    private int frequency;
    private int period;

    /**
     * Create a new schedule
     */
    public ScheduleImpl() {
    }

    /**
     * Create a new schedule
     * @param name Name of schedule
     * @param days Days
     * @param startTime Start time - only the hours and minutes are significant
     * @param endTime End time - only the hours and minutes are significant
     */
    public ScheduleImpl(String name, Set<Integer> days, Date startTime,
            Date endTime) {
        this.name = name;
        this.days = days;
        this.startTime = startTime;
        this.endTime = endTime;
    }
    
    /**
     * Get the name of the schedule
     * @return Name of schedule
     */
    public String getName() {
        return this.name;
    }

    /**
     * Set the name
     * @param name Name of schedule
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * Get a description of the schedule
     * @return Textual representation of the schedule
     */
    public String getDescription() {
        return ScheduleUtils.scheduleToText(this);
    }

    /**
     * Get the days on which the schedule is active
     * @return Days
     */
    public Set<Integer> getDays() {
        return days;
    }

    /**
     * Set the days on which the schedule is active
     * @param days
     */
    public void setDays(Set<Integer> days) {
        this.days = days;
    }
    
    /**
     * Get the start time, irrespective of day, when messages could start
     * @return Time of day
     */
    public Date getStartTime() {
        return startTime;
    }

    /**
     * Set the start time, irrespective of day, when messages could start
     * @param startTime Time of day
     */
    public void setStartTime(Date startTime) {
        this.startTime = startTime;
    }

    /**
     * Get the end time, irrespective of day, after which messages will stop
     * @return Time of day
     */
    public Date getEndTime() {
        return endTime;
    }

    /**
     * Set the end time, irrespective of day, after which messages will stop
     * @param endTime Time of day
     */
    public void setEndTime(Date endTime) {
        this.endTime = endTime;
    }

    /**
     * Get the frequency
     * @return Number of times during the period that a message should appear
     */
    public int getFrequency() {
        return this.frequency;
    }

    /**
     * Set the Number of times during the period that a message should appear
     * @param frequency Frequency of messages relative to period
     */
    public void setFrequency(int frequency) {
        this.frequency = frequency;
    }

    /**
     * Get the period, in minutes
     * @return Period, in minutes
     */
    public int getPeriod() {
        return period;
    }

    /**
     * Set the period, in minutes
     * @param minutes Period, in minutes
     */
    public void setPeriod(int minutes) {
        this.period = minutes;
    }

    /**
     * Indicates if the schedule has regular intervals between messages
     * @return <tt>true</tt> if the time between messages is always the same
     */
    public boolean isPeriodic() {
        return true;
    }

    @Override
    public String toString() {
        return getName();
    }

}
